/**
 * Created by ${PRODUCT_NAME}.
 * User: skylerparr
 * Date: 12/26/10
 * Time: 12:00 PM
 * To change this template use File | Settings | File Templates.
 */
package com.thoughtorigin.loader.mock {
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.utils.ByteArray;

public class MockLoader extends Loader{

    public var _loadCalled: Boolean;
    public var _urlString: String;
    public var _context: LoaderContext;
    public var _closeCalled: Boolean;
    public var _content: *;
    public var _unloadAndStop: Boolean;
    public var _unload: Boolean;
    public var _contentLoaderInfo: LoaderInfo;

    public function MockLoader() {
    }

    override public function get contentLoaderInfo():LoaderInfo {
        return _contentLoaderInfo;
    }

    override public function load(request:URLRequest, context:LoaderContext = null):void {
        _loadCalled = true;
        _urlString = request.url;
        _context = context;
    }

    override public function loadBytes(bytes:ByteArray, context:LoaderContext = null):void {
    }

    override public function close():void {
        _closeCalled = true;
    }

    override public function get content():DisplayObject {
        return _content
    }

    override public function unloadAndStop(gc:Boolean = true):void {
        _unloadAndStop = true;
    }

    override public function unload():void {
        _unload = true;
    }

    public function simulateProgress(bytesLoaded: Number, bytesTotal: Number): void {
        contentLoaderInfo.dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS, false, false, bytesLoaded, bytesTotal));
    }

    public function simulateComplete(): void {
        contentLoaderInfo.dispatchEvent(new Event(Event.COMPLETE));
    }

    public function simulateSecurityError(): void {
        contentLoaderInfo.dispatchEvent(new SecurityErrorEvent(SecurityErrorEvent.SECURITY_ERROR));
    }

    public function simulateNetworkError(): void {
        contentLoaderInfo.dispatchEvent(new IOErrorEvent(IOErrorEvent.NETWORK_ERROR));
    }

    public function simulateIOError(): void {
        contentLoaderInfo.dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR));
    }
}
}

